package com.itheima.ydd.controller;


import com.itheima.ydd.common.R;
import com.itheima.ydd.dto.SysMenuDto;
import com.itheima.ydd.pojo.SysMenu;
import com.itheima.ydd.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sys_menu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;
    /**
     * 菜单修改方法:根据id修改
     *
     * @param sysMenu
     * @return
     */
    @PostMapping("update")
    public ResponseEntity<R<String>> update(@RequestBody SysMenu sysMenu) {
        return sysMenuService.updateSysmenu(sysMenu);
    }

    /**
     * 菜单删除方法,根据id删除
      * @return
     */
    @GetMapping("del")
    public ResponseEntity<R<String>> delete(Integer id){
       return sysMenuService.deleteSysMenu(id);
    }

    /**
     * 查询所有的菜单
     * @param
     * @return
     */
    @GetMapping("allData")
    public ResponseEntity<R<List<SysMenuDto>>> find(){
        return sysMenuService.findAllData();
    }


    /**
     * 新增菜单功能
     * @param sysMenu
     * @return
     */
    @PostMapping("add")
    public ResponseEntity<R<String>> add(@RequestBody SysMenu sysMenu){
        return sysMenuService.addSysMenu(sysMenu);
    }

    /**
     * 根据id查询单个菜单,用于回显数据
     * @param id
     * @return
     */
    @GetMapping("rowInfo")
    public ResponseEntity<R<SysMenu>> getById(Integer id){
        return sysMenuService.getSysMenuByID(id);
    }



}
